package com.sheep.pattern.chain;

/**
 * 采用链表来实现责任链
 *
 * @author wangze
 * @date 2021-03-12 10:09.
 **/
public class HandlerChain {

	private Handler header;
	private Handler tailer;


	public void addHandler(Handler handler) {
		handler.setNextHandler(null);
		if (header == null) {
			header = handler;
			tailer = handler;
		}
		// 设置下一个执行节点为Handler
		tailer.setNextHandler(handler);
		// 设置最后一个节点为当前Handler
		tailer=handler;
	}

	public void  handle(){
		if(header!=null){
			header.execute();
		}
	}

}
